//
//  OrderModel.m
//  TestProject6
//
//  Created by JasonLee on 14/12/12.
//  Copyright (c) 2014年 JasonLee. All rights reserved.
//

#import "OrderModel.h"

@implementation OrderModel

- (OrderModel *)initWithDictionary:(NSDictionary *)dic{
    if(self = [super init]){
        //self.order_id = dic[@"id"];
        self.order_code = dic[@"orderSN"];
        self.order_datetime = dic[@"orderTime"];
        self.order_totalPrice = dic[@"orderAmount"];
        self.order_seller = dic[@"desc"];
        self.order_status = [dic[@"orderStatus"] intValue];
        self.order_refundStatus = [dic[@"refundStatus"] intValue];
        self.order_confirmStatus = [dic[@"confirmStatus"]intValue];
        NSString *string = nil;
        UIColor *color = nil;
        if(self.order_refundStatus == 0){
            switch (self.order_status) {
            case 0:
                color = [UIColor orangeColor];
                string = @"待支付";
                break;
            case 1:
                color = [UIColor colorWithRed:40/255.0 green:220/255.0 blue:100/255.0 alpha:1];
                //color = [UIColor grayColor];
                string = @"支付成功";
                break;
            case 2:
                color = [UIColor grayColor];
                string = @"已关闭";
                break;
            case 3:
                color = [UIColor grayColor];
                string = @"已取消";
                break;
            default:
                string = @"";
                break;
            }
        }else{
            if(self.order_confirmStatus == 0){
                color = [UIColor redColor];
                string = @"退款中";
            }else{
                color = [UIColor colorWithRed:25/255.0 green:180/255.0 blue:220/255.0 alpha:1];
                //color = [UIColor redColor];
                string = @"退款成功";
            }
            //
        }
        self.order_action_color = color;
        self.order_action = string;
        self.order_phone = [[NSUserDefaults standardUserDefaults]objectForKey:@"Mobile"];
    }
    return self;
}

+ (OrderModel *)statusWithDictionary:(NSDictionary *)dic{
    OrderModel *order = [[OrderModel alloc]initWithDictionary:dic];
    return order;
}


- (NSString *)getOrder{
    NSString *string = [[NSString alloc]initWithFormat:@"%@, %@, %@ ,%@, %@, %@;", 
                        self.order_code,
                        self.order_datetime,
                        self.order_totalPrice,
                        self.order_seller,
                        self.order_action,
                        self.order_phone];
    return string;
}

@end
